package heima.lm.oschina.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import heima.lm.oschina.common.CommonPager;
import heima.lm.oschina.utils.HttpUtils;

/**
 * Created by Administrator on 2017/4/1 0001.
 * Fragment的基类
 */

public abstract class BaseFragment extends Fragment {

    public CommonPager mCommonPager;

    public BaseFragment() {
        mCommonPager = new CommonPager() {
            @Override
            protected void loadData() {
                BaseFragment.this.loadData();
            }

            @Override
            protected void loadSuccessPager() {
                BaseFragment.this.loadSuccessPager();
            }
        };
    }

    protected abstract void loadSuccessPager();

    protected abstract void loadData();

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return mCommonPager.mRootView;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        //mCommonPager.enableNetwork = HttpUtils.checkNet();
        if (isVisibleToUser && !mCommonPager.isLoadedData) {
            mCommonPager.dynamic();
        }
    }
}
